package day0716;

public class Test9 {
    public static void main(String[] args) {
        MyThread1 t1 = new MyThread1();
        t1.start();//会调用run方法

        MyRunnable2 t2 = new MyRunnable2();
        Thread t3 = new Thread(t2);//线程对象
        t3.start();
    }
}

class MyRunnable2  implements Runnable{
    public void run() {
        for (int i = 0; i < 20; i++) {
            System.out.println("线程2：" + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}



class MyThread1 extends Thread {
    public void run() {
        for (int i = 0; i < 20; i++) {
            System.out.println("线程1：" + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
